//
//  Contact_RoleTableViewCell.m
//  HuaRun2
//
//  Created by admin on 17/9/2.
//  Copyright © 2017年 Sunny. All rights reserved.
//

#import "Contact_RoleTableViewCell.h"
#import "LineView.h"
#import "Contact_RoleModel.h"

@interface Contact_RoleTableViewCell ()

//时区Btn
@property (nonatomic, strong) UIButton * timeBtn;
//时区Btn
@property (nonatomic, strong) UIButton * locationBtn;

//时区
@property (nonatomic, strong) UILabel * timeLab;
//时区 的下一行
@property (nonatomic, strong) UILabel * timeLab1;

//位置
@property (nonatomic, strong) UILabel * locationLab;
//位置的下一行
@property (nonatomic, strong) UILabel * locationLab1;

//时区Btn
@property (nonatomic, strong) UIButton * noteBtn;
//位置
@property (nonatomic, strong) UILabel * noteLab;

//分割线
@property (nonatomic, strong) LineView * lineView;
@property(nonatomic, assign)int num;
@end

@implementation Contact_RoleTableViewCell
#pragma mark - life cycle
- (void)dealloc {
    NSLog(@"%@ dealloc", [self class]);
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
//        self.contentView.backgroundColor = [UIColor whiteColor];// RGBA(249, 249, 249, 1);
//        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        [self viewInit];
        [self layoutInit];
    }
    return self;
}

- (void)viewInit {
    
    [super viewInit];
    int num = [self getRandomNumber:1 to:2];
    self.num = num;
    
    [self.contentView addSubview:self.timeBtn];
    [self.contentView addSubview:self.timeLab];
    [self.contentView addSubview:self.timeLab1];
    
    [self.contentView addSubview:self.locationBtn];
    [self.contentView addSubview:self.locationLab];
    [self.contentView addSubview:self.locationLab1];

    [self.contentView addSubview:self.noteBtn];
    [self.contentView addSubview:self.noteLab];

    [self.contentView addSubview:self.lineView];

}

- (void)layoutInit {
//    [super layoutInit];
    
    weakself(ws);
    [self.backView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(ws.contentView).offset(kMargin10);
        make.right.mas_equalTo(ws.contentView).offset(-kMargin10);
        make.top.mas_equalTo(ws.contentView).offset(kMargin10);
        make.bottom.mas_equalTo(ws.contentView).offset(-0);
    }];
    
    [self.timeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.backView).offset(kMargin10 * 3);
        make.left.mas_equalTo(ws.backView.mas_left).offset(kMargin10);
        make.size.mas_equalTo(CGSizeMake(15, 15));
    }];
    
    [self.timeLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.timeBtn);
        make.left.mas_equalTo(ws.timeBtn.mas_right).offset(kMargin10);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-kMargin10);
    }];

    [self.timeLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.timeLab.mas_bottom);
        make.left.right.mas_equalTo(ws.timeLab).offset(0);
    }];
    
    [self.locationBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.timeLab1.mas_bottom).offset(kMargin10/2);
        make.left.mas_equalTo(ws.timeBtn);
        make.size.mas_equalTo(ws.timeBtn);
    }];
    
    [self.locationLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.locationBtn);
        make.left.mas_equalTo(ws.locationBtn.mas_right).offset(kMargin10);
        make.right.mas_equalTo(ws.backView.mas_right).offset(-kMargin10);
    }];

    [self.locationLab1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.locationLab.mas_bottom);
        make.left.right.mas_equalTo(ws.locationLab).offset(0);
    }];

    [self.noteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.locationLab1.mas_bottom).offset(kMargin10/2);
        make.left.mas_equalTo(ws.timeBtn);
        make.size.mas_equalTo(ws.timeBtn);
    }];

    [self.noteLab mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.noteBtn);
        make.left.right.mas_equalTo(ws.locationLab).offset(0);
    }];

    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(ws.backView);
        make.left.mas_equalTo(ws.backView).offset(kMargin10);
        make.right.mas_equalTo(ws.locationLab).offset(0);
        make.height.mas_equalTo(1);
    }];

}

- (void)setRoleModel:(Contact_RoleModel *)roleModel {
    _roleModel = roleModel;
    
    _timeLab.text = [self commonStringWithStr:roleModel.role];
    _timeLab1.text = [self commonStringWithStr:roleModel.role];
    
    _locationLab.text = [self commonStringWithStr:roleModel.accountName];
    _locationLab1.text = [self commonStringWithStr:roleModel.accountName];

    _noteLab.text = [self commonStringWithStr:roleModel.remark];
}

- (NSString *)commonStringWithStr:(NSString *)str {
    BOOL isEmpty = [NSString isemptyStr: str];
    return isEmpty ? @" " : str;
}

- (UILabel *)timeLab {
    if (!_timeLab) {
        self.timeLab = [UILabel new];
        _timeLab.textAlignment = NSTextAlignmentLeft;
        _timeLab.font = kGeneralFontSize;
        _timeLab.textColor = [UIColor colorWithHex:@"3c3c3c"];

    }
    return _timeLab;
}

- (UILabel *)timeLab1 {
    if (!_timeLab1) {
        self.timeLab1 = [UILabel new];
        _timeLab1.textAlignment = NSTextAlignmentLeft;
        _timeLab1.font = kGeneralFontSize;
        _timeLab1.textColor = [UIColor colorWithHex:@"3c3c3c"];
    }
    return _timeLab1;
}

- (UILabel *)locationLab {
    if (!_locationLab) {
        self.locationLab = [UILabel new];
        _locationLab.textAlignment = NSTextAlignmentLeft;
        _locationLab.font = kGeneralFontSize;
        _locationLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _locationLab.text = @"0helloworld\nhelloworld\nhelloworld";
//        _locationLab.numberOfLines = 2;
    }
    return _locationLab;
}

- (UILabel *)locationLab1 {
    if (!_locationLab1) {
        self.locationLab1 = [UILabel new];
        _locationLab1.textAlignment = NSTextAlignmentLeft;
        _locationLab1.font = kGeneralFontSize;
        _locationLab1.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _locationLab1.text = @"1helloworld\nhelloworld\nhelloworld";
//        _locationLab.numberOfLines = 2;
    }
    return _locationLab1;
}

- (UILabel *)noteLab {
    if (!_noteLab) {
        self.noteLab = [UILabel new];
        _noteLab.textAlignment = NSTextAlignmentLeft;
        _noteLab.font = kGeneralFontSize;
        _noteLab.textColor = [UIColor colorWithHex:@"3c3c3c"];
        _noteLab.text = @"1helloworld\nhelloworld\nhelloworld";
        _noteLab.numberOfLines = 2;
    }
    return _noteLab;
}

//- (UILabel *)noteLab1 {
//    if (!_noteLab1) {
//        self.noteLab1 = [UILabel new];
//        _noteLab1.textAlignment = NSTextAlignmentLeft;
//        _noteLab1.font = kGeneralFontSize;
//        _noteLab1.textColor = [UIColor colorWithHex:@"3c3c3c"];
//        _noteLab1.text = @"1helloworld\nhelloworld\nhelloworld";
//    }
//    return _noteLab1;
//}

- (UIButton *)locationBtn {
    if (!_locationBtn) {
        self.locationBtn = [UIButton new];
        NSString * name = [self getRandomImageWithName:@"gongsi_juese"];
        [_locationBtn setBackgroundImage:[UIImage imageNamed:name]
                                forState:(UIControlStateNormal)];
    }
    return _locationBtn;
}
-(int)getRandomNumber:(int)from to:(int)to
{
    return (int)(from + (arc4random() % (to - from + 1)));
}

- (NSString *)getRandomImageWithName:(NSString *)name {
    
    return [NSString stringWithFormat:@"%@%d", name, _num];
}

- (UIButton *)timeBtn {
    if (!_timeBtn) {
        self.timeBtn = [UIButton new];
        NSString * name = [self getRandomImageWithName:@"lianxiren_juese"];
        [_timeBtn setBackgroundImage:[UIImage imageNamed:name]
                            forState:(UIControlStateNormal)];
    }
    return _timeBtn;
}

- (UIButton *)noteBtn {
    if (!_noteBtn) {
        self.noteBtn = [UIButton new];
        NSString * name = [self getRandomImageWithName:@"beizhu_juese"];
        [_noteBtn setBackgroundImage:[UIImage imageNamed:name]
                            forState:(UIControlStateNormal)];
    }
    return _noteBtn;
}

- (LineView *)lineView {
    if (!_lineView) {
        self.lineView =  [LineView new];
        
    }
    return _lineView;
}
@end
